<?php
ob_start();
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
include '../operations/connection.php';

$id_employee = $_SESSION['IDEmployee'];
if(isset($_REQUEST['xacnhan'])){
	$mang=$_SESSION['listCalendar'];
	foreach ($mang as $value => $giatri){
		$kq = mysql_query("SELECT * from calendar c where c.id =".$giatri[0]);
		if(mysql_num_rows($kq)>=1)
			mysql_query("UPDATE `calendar` SET `name`='$giatri[1]', `date`='$giatri[2]',`isDelete`='$giatri[3]',`content`='$giatri[4]' WHERE (`id`='$giatri[0]')");
		//else
			//mysql_query("INSERT INTO `calendar` (`name`, `date`, `employee`, `isDelete`) VALUES ('$giatri[1]', '$giatri[2]', '$id_employee', '$giatri[3]')");
	}
	
	$idCalendar=$_REQUEST['idCalendar'];
	$nameCalendar=$_REQUEST['nameCalendar'];
	$contentCalendar=$_REQUEST['contentCalendar'];
	$date=$_REQUEST['date'];
	
	for($i=0;$i<count($idCalendar);$i++){
		$kq = mysql_query("SELECT * from calendar c where c.id =".$idCalendar[$i]);
		if(mysql_num_rows($kq)>=1)
			mysql_query("UPDATE `calendar` SET `name`='$nameCalendar[$i]', `date`='$date[$i]', `content`='$contentCalendar[$i]' WHERE (`id`='$idCalendar[$i]')");
		else
			mysql_query("INSERT INTO `calendar` (`name`,`content`, `date`,`employee`) VALUES ('$nameCalendar[$i]','$contentCalendar[$i]', '$date[$i]', '$id_employee')");
	}
	unset($_SESSION['listCalendar']);
}
mysql_close($connection);

header("Location: ../calendar.php");
ob_flush();
?>